/**
* Copyright (C) 2018-2020
* All rights reserved, Designed By www.gzchengguo.cn
* 注意：
* 本软件为www.gzchengguo.cn开发研制，未经购买不得商用
* 购买后可获得全部源代码（禁止转卖、分享、上传到码云、github等开源平台）
* 一经发现盗用、分享等行为，将追究法律责任，后果自负
*/
package link.chengguo.orangemall.modules.user.service.impl;


import link.chengguo.orangemall.common.service.impl.BaseServiceImpl;
import link.chengguo.orangemall.modules.user.domain.OrangeUserTaskFinish;
import link.chengguo.orangemall.modules.user.service.OrangeUserTaskFinishService;
import link.chengguo.orangemall.modules.user.service.mapper.OrangeUserTaskFinishMapper;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


/**
 * <p>
 * 用户任务完成记录表 服务实现类
 * </p>
 *
 * @author chengguo
 * @since 2019-12-07
 */
@Slf4j
@Service
@AllArgsConstructor
@Transactional(rollbackFor = Exception.class)
public class OrangeUserTaskFinishServiceImpl extends BaseServiceImpl<OrangeUserTaskFinishMapper, OrangeUserTaskFinish> implements OrangeUserTaskFinishService {

    private final OrangeUserTaskFinishMapper orangeUserTaskFinishMapper;


    /**
     * 设置任务完成
     * @param uid uid
     * @param taskId 任务id
     */
    @Override
    public void setFinish(Long uid, int taskId) {
        int count = this.lambdaQuery()
                .eq(OrangeUserTaskFinish::getUid,uid)
                .eq(OrangeUserTaskFinish::getTaskId,taskId)
                .count();
        if(count == 0){
            OrangeUserTaskFinish userTaskFinish = new OrangeUserTaskFinish();
            userTaskFinish.setUid(uid);
            userTaskFinish.setTaskId(taskId);
            orangeUserTaskFinishMapper.insert(userTaskFinish);
        }
    }



}
